﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

using Microsoft.AspNet.SignalR.Client.Hubs;

namespace Bronze.XXT.PhoneServer.Common
{
    public class SignalRHelper
    {
        static IHubProxy hub;
        static Newtonsoft.Json.Converters.IsoDateTimeConverter timeConverter;

        static SignalRHelper()
        {

            timeConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter();
            timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";

            var hubUrl = ConfigurationManager.AppSettings["hubUrl"];

            var hubCon = new HubConnection(hubUrl);

            hub = hubCon.CreateHubProxy("attendHub");
            hubCon.Start().Wait();
        }

        public static void SendMssage(object[] parameters)
        {
            parameters[1] = Newtonsoft.Json.JsonConvert.SerializeObject(parameters[1], Newtonsoft.Json.Formatting.Indented, timeConverter);
            hub.Invoke("Send", parameters);
        }
    }
}
